// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    index: 1,
    count: 8,
    actionList: [{ id: 1, name: '呼啦圈', img: '/assets/images/qs1.GIF' },
    { id: 2, name: '举重', img: '/assets/images/qs2.GIF' },
    { id: 3, name: '跳绳', img: '/assets/images/qs3.GIF' },
    { id: 4, name: '哑铃', img: '/assets/images/qs4.GIF' },],
    total:8,
    timer:null
  },
  changeTimer(){
    if (this.data.index>this.data.actionList.length) {
      wx.showModal({
        cancelColor: '#000',
        cancelText: '休息一下',
        confirmColor: '#F40',
        confirmText: '继续运动',
        content: '是否继续',
        title: '提示',
        success: (result) => {
          if (result.cancel) {
            wx.navigateTo({
              url: '/pages/first/first'
            })
          }else{
            this.setData({
              index:1,
              count:8
            })
            this.changeTimer()
          }
        }
      })
    }else{
      if (this.data.count<=0) {
        let newindex = this.data.index+1
        this.setData({
          index:newindex,
          count:8
        })
        this.changeTimer()
      }else{
        setTimeout(()=>{
          let newcount=this.data.count-1
          this.setData({
            count:newcount
          })
          this.changeTimer()
        },1000)
      }
    }
  },
  onLoad() {
    this.changeTimer()
  }
})
